import { reqCategoryListData , reqGetBannerListData , reqGetFloorsListData } from "../../api";
const state = {
  categoryList: [],
  bannerList:[],
  floorsList:[]
};
const actions = {
  // 1. 获取三级分数数据
  async getCategoryListData(context) {
    const result = await reqCategoryListData();
    if (result.code === 200) {
      // 如果成功 则提交给mutations中的方法
      context.commit("GET_CATEGORY_LIST_DATA", result);
    } else {
      console.log(result.message);
    }
  },
  // 2.获取mock轮播图数据
  async getBannerListData({commit}){
    const result = await reqGetBannerListData();
    if(result.code===200){
      commit('GET_BANNER_LIST_DATA',result)
    }else{
      console.log(result.message)
    }
  },
  // 3获取mock楼层数据
  async getFloorsListData({commit}){
    const result = await reqGetFloorsListData()
    if(result.code===200){
      commit('GET_FLOORS_LIDT_DATA',result)
    }else{
      console.log(result.message)
    }
  }
};
const mutations = {
  GET_CATEGORY_LIST_DATA(state, payload) {
    // console.log(12,payload);
    state.categoryList = payload.data;
  },
  GET_BANNER_LIST_DATA(state,payload){
    state.bannerList=payload.data
  },
  GET_FLOORS_LIDT_DATA(state,payload){
    state.floorsList=payload.data
  }
};
const getters = {};

// 4. 导出对象
export default {
  namespaced: true, // 既然是分模块进行开发了,一定要开启命名空间
  state,
  actions,
  mutations,
  getters,
};